﻿<cfscript>
/** 
* @hint "system - globe options & setting "
*/ 

component 
	extends="MachII.framework.Listener" 
	displayname="acadmicManager.listeners.system.globeSettingListener" 
	output=false 
	{
	
	/**
	* @hint "Configures this listener as part of the Mach-II framework"
	*/
	public void function configure() output=false {} 

	/**
	* @hint "评教相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function getEvaluateSetting ( required MachII.framework.Event event ) output=false {
		
		var sql = "";
		var queryObj = "";
		var rs_options = queryNew("prop_name, prop_value");
		
		
		sql = "SELECT prop_name, prop_value FROM t_globe_option WHERE prop_name LIKE :key ORDER BY prop_name ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="key", value="EVALSYS.%", cfsqltype="cf_sql_varchar" );
		
		rs_options = queryObj.execute( sql=sql ).getResult();
		
		
		for ( var a=1; a LTE rs_options.recordCount; a++ ) {
			event.setArg( rs_options["prop_name"][a], rs_options["prop_value"][a] );
		}
		
	}

	/**
	* @hint "保存评教相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function setEvaluateSetting ( required MachII.framework.Event event ) output=false {
		
		var stuDateStart = event.getArg("StuDateStart");
		var stuDateEnd = event.getArg("StuDateEnd");
		var disableMarkView = event.getArg("DisableMarkView", "0");
		
		var sql = "";
		var queryObj = "";
		
		var rs_check = "";
		
		var keyName = "";
		var keyValue = "";
		
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			if ( len(stuDateStart) ) {
				
				keyName = "EVALSYS.STU.DateStart";
				keyValue = replace( stuDateStart, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}

			if ( len(stuDateEnd) ) {
				
				keyName = "EVALSYS.STU.DateEnd";
				keyValue = replace( stuDateEnd, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(disableMarkView) ) {
				
				keyName = "EVALSYS.STU.DisableMarkView";
				keyValue = yesNoFormat(disableMarkView);
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
		}
		
	}
	
	/**
	* @hint "选课相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function getChooseSetting ( required MachII.framework.Event event ) output=false {
		
		var sql = "";
		var queryObj = "";
		var rs_options = queryNew("prop_name, prop_value");
		
		
		sql = "SELECT prop_name, prop_value FROM t_globe_option WHERE prop_name LIKE :key ORDER BY prop_name ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="key", value="CHOOSE.%", cfsqltype="cf_sql_varchar" );
		
		rs_options = queryObj.execute( sql=sql ).getResult();
		
		
		for ( var a=1; a LTE rs_options.recordCount; a++ ) {
			event.setArg( rs_options["prop_name"][a], rs_options["prop_value"][a] );
		}
		
	}
	
	
	/**
	* @hint "保存选课相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function setChooseSetting ( required MachII.framework.Event event ) output=false {
		
		var depDateStart = event.getArg("DepDateStart");
		var depDateEnd = event.getArg("DepDateEnd");
		
		var sql = "";
		var queryObj = "";
		
		var rs_check = "";
		
		var keyName = "";
		var keyValue = "";
		
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			if ( len(depDateStart) ) {
				
				keyName = "CHOOSE.DEP.DateStart";
				keyValue = replace( depDateStart, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(depDateEnd) ) {
				
				keyName = "CHOOSE.DEP.DateEnd";
				keyValue = replace( depDateEnd, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			

		}
	}
	
	
	/**
	* @hint "期末考试安排相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function getFinalExamSetting ( required MachII.framework.Event event ) output=false {
		
		var sql = "";
		var queryObj = "";
		var rs_options = queryNew("prop_name, prop_value");
		
		
		sql = "SELECT prop_name, prop_value FROM t_globe_option WHERE prop_name LIKE :key ORDER BY prop_name ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="key", value="EXAM.FINAL.%", cfsqltype="cf_sql_varchar" );
		
		rs_options = queryObj.execute( sql=sql ).getResult();
		
		
		for ( var a=1; a LTE rs_options.recordCount; a++ ) {
			event.setArg( rs_options["prop_name"][a], rs_options["prop_value"][a] );
		}
		
	}
	
	
	/**
	* @hint "教学任务安排相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function getTaskSetting ( required MachII.framework.Event event ) output=false {
		
		var sql = "";
		var queryObj = "";
		var rs_options = queryNew("prop_name, prop_value");
		
		
		sql = "SELECT prop_name, prop_value FROM t_globe_option WHERE prop_name LIKE :key ORDER BY prop_name ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="key", value="TASK.%", cfsqltype="cf_sql_varchar" );
		
		rs_options = queryObj.execute( sql=sql ).getResult();
		
		
		for ( var a=1; a LTE rs_options.recordCount; a++ ) {
			event.setArg( rs_options["prop_name"][a], rs_options["prop_value"][a] );
		}
		
	}
	
	
	/**
	* @hint "保存教学任务安排相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function setTaskSetting ( required MachII.framework.Event event ) output=false {
		
		var dateStart = event.getArg("DateStart");
		var dateEnd = event.getArg("DateEnd");
		
		var limiteB2 = event.getArg("LimiteB2");
		var limiteS3 = event.getArg("LimiteS3");

		var limiteS2 = event.getArg("LimiteS2");
		
		var optEntity = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			if ( len(dateStart) ) {
				
				keyName = "TASK.DateStart";
				keyValue = replace( dateStart, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(dateEnd) ) {
				
				keyName = "TASK.DateEnd";
				keyValue = replace( dateEnd, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(limiteB2) and isNumeric(limiteB2) ) {
				
				keyName = "TASK.LIMITE.B2";
				keyValue = limiteB2;
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(limiteS3) and isNumeric(limiteS3) ) {
				
				keyName = "TASK.LIMITE.S3";
				keyValue = limiteS3;
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(limiteS2) and isNumeric(limiteS2) ) {
				
				keyName = "TASK.LIMITE.S2";
				keyValue = limiteS2;
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
		}
	}
	
	
	/**
	* @hint "考试安排相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function getExamSetting ( required MachII.framework.Event event ) output=false {
		
		var sql = "";
		var queryObj = "";
		var rs_options = queryNew("prop_name, prop_value");
		
		
		sql = "SELECT prop_name, prop_value FROM t_globe_option WHERE prop_name LIKE :key ORDER BY prop_name ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="key", value="EXAM.%", cfsqltype="cf_sql_varchar" );
		
		rs_options = queryObj.execute( sql=sql ).getResult();
		
		
		for ( var a=1; a LTE rs_options.recordCount; a++ ) {
			event.setArg( rs_options["prop_name"][a], rs_options["prop_value"][a] );
		}

	}
	
	
	/**
	* @hint "保存考试相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function setExamSetting ( required MachII.framework.Event event ) output=false {
		
		var finalDateStart = event.getArg("FinalDateStart");
		var finalDateEnd = event.getArg("FinalDateEnd");
		var finalCourseConflict = event.getArg("FinalCourseConflict");
		
		var optEntity = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			if ( len(finalDateStart) ) {
				
				keyName = "EXAM.FINAL.DateStart";
				keyValue = replace( finalDateStart, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(finalDateEnd) ) {
				
				keyName = "EXAM.FINAL.DateEnd";
				keyValue = replace( finalDateEnd, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";

					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(finalCourseConflict) and isNumeric(finalCourseConflict) ) {
				
				keyName = "EXAM.FINAL.CourseConflict";
				keyValue = finalCourseConflict;
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
		}
	}
	
	/**
	* @hint "校内学生转专业相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function getSubjectChangeSignSetting ( required MachII.framework.Event event ) output=false {
		
		var sql = "";
		var queryObj = "";
		var rs_options = queryNew("prop_name, prop_value");
		
		
		sql = "SELECT prop_name, prop_value FROM t_globe_option WHERE prop_name LIKE :key ORDER BY prop_name ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="key", value="SBJCHG.%", cfsqltype="cf_sql_varchar" );
		
		rs_options = queryObj.execute( sql=sql ).getResult();
		
		
		for ( var a=1; a LTE rs_options.recordCount; a++ ) {
			event.setArg( rs_options["prop_name"][a], rs_options["prop_value"][a] );
		}

	}
	
	/**
	* @hint "保存校内学生转专业相关设置"
	* 
	* @event "MachII Event Object"
	*/
	public void function setSubjectChangeSignSetting ( required MachII.framework.Event event ) output=false {
		
		var signDateStart = event.getArg("DateStart");
		var signDateEnd = event.getArg("DateEnd");
		var gpaReq = event.getArg("CreditPointAvgRequired");
		var gpa = event.getArg("CreditPointAvg");
		
		var optEntity = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			if ( len(signDateStart) ) {
				
				keyName = "SBJCHG.DateStart";
				keyValue = replace( signDateStart, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(signDateEnd) ) {
				
				keyName = "SBJCHG.DateEnd";
				keyValue = replace( signDateEnd, "-", "", "ALL" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(gpaReq) and isNumeric(gpaReq) ) {
				
				keyName = "SBJCHG.CreditPointAvgRequired";
				keyValue = numberFormat( gpaReq, "_.__" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}
			
			if ( len(gpa) and isNumeric(gpa) ) {
				
				keyName = "SBJCHG.CreditPointAvg";
				keyValue = numberFormat( gpa, "_.__" );
				
				sql = "SELECT 1 FROM t_globe_option WHERE prop_name = :key ";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
				
				rs_check = queryObj.execute( sql=sql ).getResult();
				
				if ( rs_check.recordCount ) { 
					
					sql = "UPDATE t_globe_option SET prop_value = :value WHERE prop_name = :key ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				else { 
				
					sql = "INSERT INTO t_globe_option ( prop_name, prop_value ) VALUES ( :key, :value ) ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="key", value=keyName, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="value", value=keyValue, cfsqltype="cf_sql_varchar" );
					
					queryObj.execute( sql=sql );
					
				}
				
			}

		}
		
	}
	
	

}

</cfscript>